# -*- coding: utf-8 -*-
"""顶部搜索栏页面对象。位于 base.html，可在任何页面使用。"""

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

from .base import BasePage
from common.log import log


class SearchBar(BasePage):
    """封装搜索输入与触发操作"""

    INPUT = (By.CSS_SELECTOR, "input.input_text")
    BUTTON = (By.CSS_SELECTOR, "input.input_btn")

    def search(self, keyword: str):
        log.info(f"在搜索框输入: {keyword}")
        self.type(self.INPUT, keyword)
        self.click(self.BUTTON)

    def wait_alert(self, timeout: int = 3):
        try:
            return WebDriverWait(self.driver, timeout).until(EC.alert_is_present())
        except Exception:
            return None 